package jse;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class TestHashMap {
	public static void main(String[] args) {/*
		HashMap<String,User> users=new HashMap<String, User>();
		users.put("tom", new User(1,"tom"));
		users.put("jerry", new User(2,"jerry"));
		Scanner sc=new Scanner(System.in);
		String name=sc.nextLine();
		while(true){
			if(!users.containsKey(name)){
				System.out.println("莫有注册");
				break;
			}
			User user=new User();
			user=(User)users.get(name);
			if(user.getId()==1){
				System.out.println("登录成功");
				break;
			}
		}
		
	*/
		String str="我醒了，我要洗脸了。";
		Map<Character,Integer> map=count(str);
		Collection<Integer> values=map.values();
		int all=0;
		Iterator<Integer> ite=values.iterator();
		while(ite.hasNext()){
			int i=ite.next();
			all+=i;
		}
		Set<Character> keys=map.keySet();
		for(Iterator i=keys.iterator();i.hasNext();){
			char c=(Character)i.next();
			int count=map.get(c);
			System.out.println(
					c+"\t"
					+count+"\t"
					+((double)count/all*100)
					);
		}
		
		
	}
	public static  HashMap<Character, Integer> count(String str){
		 HashMap<Character,Integer> map=new HashMap<Character, Integer>();
		 for(int i=0;i<str.length();i++){
			 char c=str.charAt(i);
			 Integer count=map.get(c);
			 count=count==null ? 1 : count+1;
			 map.put(c, count);
		 }
		return map;
	}
}
 